import numpy as np
from PySide6.QtWidgets import (QWidget, QDialog, QTabWidget)
from lttb import downsample
import json
import os

from PySide6.QtCore import Qt, QPointF, QTimer
from PySide6.QtCharts import QChart, QLineSeries, QDateTimeAxis, QValueAxis, QChartView
from PySide6.QtGui import QPainter, QPen, QColor, QVector3D
from PySide6.QtWidgets import QWidget, QSizePolicy
from PySide6.QtDataVisualization import QAbstract3DGraph, QScatter3DSeries, QAbstract3DSeries, QScatterDataItem

from Auxiliary_interface.image import Ui_image  #登录界面UI文件，并编写逻辑
from Auxiliary_interface import chartview
from Auxiliary_interface.customscatter import CustomScatter  # （实时）3D界面对象


# 降采样算法
def largest_triangle_three_buckets(xzhou, data, threshold):
    points = np.column_stack((xzhou, data))  # 合并数据与

    downsampled = downsample(points, n_out=threshold)
    return downsampled[:, 1]


# ------------------------更新曲线为黑色虚线-----------------------
def server(line_chart, _axisX, _axisY, color, pen_style):  #chart对象 pen对象 X轴对象 Y轴对象 颜色 笔模式
    # 设置曲线的颜色和宽度
    green = QPen(color)
    green.setStyle(pen_style)
    green.setWidth(1)
    _series = QLineSeries()
    _series.setPen(green)
    line_chart.addSeries(_series)
    line_chart.legend().markers(_series)[0].setVisible(False)  # 隐藏第二条曲线的图例
    _series.attachAxis(_axisX)
    _series.attachAxis(_axisY)
    return _series


# 判断字典的层级
def get_dict_depth_iterative(d):
    """
    迭代方法计算字典的最大嵌套深度。
    :param d: 需要计算深度的字典
    :return: 字典的层级数
    """
    if not isinstance(d, dict) or not d:
        return 0
    max_depth = 1
    stack = [(d, 1)]
    while stack:
        current_dict, depth = stack.pop()
        if isinstance(current_dict, dict):
            for value in current_dict.values():
                if isinstance(value, dict):
                    stack.append((value, depth + 1))
                    max_depth = max(max_depth, depth + 1)
    return max_depth


def quxianluru(names, np_dates, points, line_chart, axis_x, axis_y, color):
    # 录入数据函数：
    #           names：此数据的名称
    #           np_dates：X轴原始数据
    #           points：Y轴原始数据
    #           line_chart：chart对象容器
    #           axis_x：日期X轴对象
    #           axis_y：对应Y轴插入对象
    green = QPen(color)
    green.setStyle(Qt.SolidLine)
    green.setWidth(1)
    series = QLineSeries()
    series.setPen(green)
    series.setName(names)
    line_chart.addSeries(series)
    line_chart.addAxis(axis_x, Qt.AlignBottom)  # 设置 x 轴的位置
    series.attachAxis(axis_x)  # 将系列与坐标轴关联
    line_chart.addAxis(axis_y, Qt.AlignLeft)  # 设置 y 轴的位置
    series.attachAxis(axis_y)  # 将系列与坐标轴关联
    shuju_zidian = {}
    pen_style = 0
    old_time = np_dates[0]
    # 将 np_dates 转换为 QPointF 对象并添加到系列
    for i in range(len(np_dates)):
        # 将 QDateTime 转换为时间戳并创建 QPointF 对象
        timestamp = np_dates[i].toMSecsSinceEpoch()
        # 然后再进行赋值
        shuju_zidian[timestamp] = points[i]  # 将数据存入字典中，以便在云框显示中获取
        if abs(np_dates[i].secsTo(old_time)) > 3:
            if pen_style:
                series = server(line_chart, axis_x, axis_y, color,
                                Qt.DotLine)  # chart对象 pen对象 X轴对象 Y轴对象 颜色 笔模式
                pen_style = 0
        else:
            if not pen_style:
                series = server(line_chart, axis_x, axis_y, color,
                                Qt.SolidLine)  # chart对象 pen对象 X轴对象 Y轴对象 颜色 笔模式
                pen_style = 1
        old_time = np_dates[i]  # 上一次时间存储
        series.append(QPointF(timestamp, points[i]))  # 使用 QPointF 来表示 (时间戳, 数据点)
    return shuju_zidian

class MainWindow(Ui_image, QDialog):
    start_old = 0
    end_old = 100
    mianban = ["聚焦(V)", "偏压(V)", "灯丝(A)", "高压(KV)", "束流(MA)", "枪室真空度", "焊室真空度", "R角度", "转台角度"]
    Xzhou = []
    shuju = []

    def __init__(self):
        super().__init__()
        self.setupUi(self)
        # 设置关闭时自动删除对象
        self.setAttribute(Qt.WA_DeleteOnClose, True)
        self.colors = [  # 不同曲线对应的颜色
            QColor(255, 0, 0), QColor(0, 255, 0), QColor(0, 0, 255), QColor(210, 105, 30),
            QColor(255, 97, 0), QColor(0, 199, 140), QColor(255, 0, 255), QColor(153, 51, 250),
            QColor(0, 114, 206), QColor(213, 94, 0), QColor(0, 158, 115), QColor(230, 159, 0),
            QColor(153, 0, 255), QColor(128, 128, 128), QColor(0, 180, 180), QColor(85, 107, 47),
            QColor(139, 69, 19), QColor(8, 46, 84)]
        self.colors_mc = [  # 不同多选框对应的颜色
            "color: #FF0000", "color: #00FF00", "color: #0000FF", "color: #D2691E",
            "color: #FF6100", "color: #00C78C", "color: #FF00FF", "color: #9933FA",
            "color: #0072CE", "color: #D55E00", "color: #009E73", "color: #E69F00",
            "color: #9900FF", "color: #808080", "color: #00B4B4", "color: #556B2F",
            "color: #8B4513", "color: #082E54"]
        self.shuju_zidian = {}  # 数据字典存储
        self.chart_view = {}

        self.time_xyz = np.empty((0, 6))  # 日期、坯组、边号、坐标存储， 用于3D图像鼠标点显示
        # 指定要操作的JSON文件名
        json_file = 'H_S_JSON/legend.json'
        # 从 JSON 文件读取字典
        with open(json_file, 'r') as file:
            self.key_v_data = json.load(file)
        # 多选状态初始化
        self.checkBox.setChecked(self.key_v_data[self.checkBox.text()])
        self.checkBox_2.setChecked(self.key_v_data[self.checkBox_2.text()])
        self.checkBox_3.setChecked(self.key_v_data[self.checkBox_3.text()])
        self.checkBox_4.setChecked(self.key_v_data[self.checkBox_4.text()])
        self.checkBox_5.setChecked(self.key_v_data[self.checkBox_5.text()])
        self.checkBox_6.setChecked(self.key_v_data[self.checkBox_6.text()])
        self.checkBox_7.setChecked(self.key_v_data[self.checkBox_7.text()])
        self.checkBox_8.setChecked(self.key_v_data[self.checkBox_8.text()])
        self.checkBox_9.setChecked(self.key_v_data[self.checkBox_9.text()])
        self.checkBox_10.setChecked(self.key_v_data[self.checkBox_10.text()])
        self.checkBox_11.setChecked(self.key_v_data[self.checkBox_11.text()])
        self.checkBox_12.setChecked(self.key_v_data[self.checkBox_12.text()])
        self.checkBox_13.setChecked(self.key_v_data[self.checkBox_13.text()])
        self.checkBox_14.setChecked(self.key_v_data[self.checkBox_14.text()])
        self.checkBox_15.setChecked(self.key_v_data[self.checkBox_15.text()])
        self.checkBox_16.setChecked(self.key_v_data[self.checkBox_16.text()])
        self.checkBox_17.setChecked(self.key_v_data[self.checkBox_17.text()])
        self.checkBox_18.setChecked(self.key_v_data[self.checkBox_18.text()])

        # 多选按钮事件绑定
        self.checkBox.stateChanged.connect(self.update_status)
        self.checkBox_2.stateChanged.connect(self.update_status)
        self.checkBox_3.stateChanged.connect(self.update_status)
        self.checkBox_4.stateChanged.connect(self.update_status)
        self.checkBox_5.stateChanged.connect(self.update_status)
        self.checkBox_6.stateChanged.connect(self.update_status)
        self.checkBox_7.stateChanged.connect(self.update_status)
        self.checkBox_8.stateChanged.connect(self.update_status)
        self.checkBox_9.stateChanged.connect(self.update_status)
        self.checkBox_10.stateChanged.connect(self.update_status)
        self.checkBox_11.stateChanged.connect(self.update_status)
        self.checkBox_12.stateChanged.connect(self.update_status)
        self.checkBox_13.stateChanged.connect(self.update_status)
        self.checkBox_14.stateChanged.connect(self.update_status)
        self.checkBox_15.stateChanged.connect(self.update_status)
        self.checkBox_16.stateChanged.connect(self.update_status)
        self.checkBox_17.stateChanged.connect(self.update_status)
        self.checkBox_18.stateChanged.connect(self.update_status)
        # 多选颜色填充
        self.checkBox.setStyleSheet(self.colors_mc[0])
        self.checkBox_2.setStyleSheet(self.colors_mc[1])
        self.checkBox_3.setStyleSheet(self.colors_mc[2])
        self.checkBox_4.setStyleSheet(self.colors_mc[3])
        self.checkBox_5.setStyleSheet(self.colors_mc[4])
        self.checkBox_6.setStyleSheet(self.colors_mc[5])
        self.checkBox_7.setStyleSheet(self.colors_mc[6])
        self.checkBox_8.setStyleSheet(self.colors_mc[7])
        self.checkBox_9.setStyleSheet(self.colors_mc[8])
        self.checkBox_10.setStyleSheet(self.colors_mc[9])
        self.checkBox_11.setStyleSheet(self.colors_mc[10])
        self.checkBox_12.setStyleSheet(self.colors_mc[11])
        self.checkBox_13.setStyleSheet(self.colors_mc[12])
        self.checkBox_14.setStyleSheet(self.colors_mc[13])
        self.checkBox_15.setStyleSheet(self.colors_mc[14])
        self.checkBox_16.setStyleSheet(self.colors_mc[15])
        self.checkBox_17.setStyleSheet(self.colors_mc[16])
        self.checkBox_18.setStyleSheet(self.colors_mc[17])

        # 按钮事件绑定
        self.pushButton.clicked.connect(self.pushButton_clicked)
        self.pushButton_2.clicked.connect(self.pushButton_2_clicked)

        # 3D窗口初始化
        self.runtime_3D_init()

        # 2D界面初始化
        self.main_tab = 0
        self.outer_tab = {}

        self.timer1 = QTimer()  # 交互更新定时器
        self.timer1.timeout.connect(self.showtime1)

        self.timer1.start(1000)

    def showtime1(self):
        isnot = True
        for key, value in self.chart_view.items():
            if value.closest_key is not None:
                if value.closest_key != value.time_key:
                    self.data_xyz.clear()
                    mask = (self.time_xyz[:, 0] == value.closest_key)  # 生成布尔掩码
                    matched_rows = list(self.time_xyz[mask, :][0])  # 筛选符合条件的行‌
                    print(matched_rows)
                    self.data_xyz.append(
                        QScatterDataItem(QVector3D(matched_rows[3], matched_rows[4], matched_rows[5])))
                    self.zhishi_c.dataProxy().resetArray(self.data_xyz)  # 修改这里，直接传递data列表
                    value.time_key = value.closest_key
                    isnot = False
        if isnot:
            self.data_xyz.clear()
            self.zhishi_c.dataProxy().resetArray([])  # 修改这里，直接传递data列表
    def show_chart(self):
        cengji = get_dict_depth_iterative(self.shuju)  # 获取字典层级
        if cengji == 2:
            self.create_tabs(self.shuju)

    def create_tabs(self, data):  # 建立tab结构
        self.main_tab = QTabWidget()
        self.horizontalLayout.addWidget(self.main_tab)
        # print(data)
        for outer_key, inner_dict in data.items():
            self.outer_tab[outer_key] = QTabWidget()
            self.main_tab.addTab(self.outer_tab[outer_key], "坯组编号：" + str(outer_key))

            for inner_key, array_data in inner_dict.items():
                self.chart_view[str(outer_key)+"-"+str(inner_key)] = self.create_chart(array_data, outer_key, inner_key)
                self.outer_tab[outer_key].addTab(self.chart_view[str(outer_key)+"-"+str(inner_key)], "边号：" + str(inner_key))

    def create_chart(self, data, pizu, bianhao):  # 绘制图像
        # 指定要操作的JSON文件名
        json_file = 'H_S_JSON/legend.json'
        # 从 JSON 文件读取字典
        with open(json_file, 'r') as file:
            self.key_v_data = json.load(file)

        data = np.array(data)
        data_x = data[:, 0]  # 第一列
        data_y = data[:, 1:19]  # 一列之外
        data_xyz = data[:, 19:22]
        data_y = data_y.transpose()  # 行列转换
        data_y = data_y.astype(float)
        min_y = np.min(data_y)  # 最小Y值
        max_y = np.max(data_y)  # 最大Y值
        data_x = data_x.tolist()
        data_y = data_y.tolist()

        # 将字典转换为一个列表，其中每个元素是一个键值对元组
        indexed_items = list(self.key_v_data.items())
        # 创建 QDateTimeAxis 实例并设置格式
        axis_x = QDateTimeAxis()
        axis_x.setFormat("hh:mm:ss.zzz")  # 设置日期时间格式
        axis_x.setTitleText(
            data_x[0].date().toString("yyyy-MM-dd") + "到" + data_x[-1].date().toString("yyyy-MM-dd"))
        axis_x.setTickCount(5)
        axis_x.setRange(data_x[0], data_x[-1])  # 设置轴的范围为 QDateTime 对象
        axis_x.setTickCount(12)  # 设置x轴间隔数量
        axis_x.setLabelsAngle(60)  # 设置显示方向，旋转角度
        for i, date_cnt in enumerate(data_xyz):     # 更新3维数据
            self.time_xyz = np.append(self.time_xyz,
                                        [[data_x[i].toMSecsSinceEpoch(), pizu, bianhao, date_cnt[0], date_cnt[2], date_cnt[1]]],
                                        axis=0)
            self.data_3D.append(QScatterDataItem(QVector3D(date_cnt[0], date_cnt[2], date_cnt[1])))
        self.series_A.dataProxy().resetArray(self.data_3D)     # 修改这里，更新3D界面点位
        # 创建 QValueAxis 实例并设置 y 轴范围
        axis_y = QValueAxis()
        axis_y.setRange(min_y-10, max_y+10)
        shuju_zidian1 = {}

        # 创建 QChart 对象
        line_chart = QChart()
        line_chart.setAnimationOptions(QChart.SeriesAnimations)
        print(indexed_items)
        for i, data_y1 in enumerate(data_y):
            if indexed_items[i][1] == True:  # 判断多选
                # 使用 get() 方法确保键存在，避免抛出 KeyError
                if indexed_items[i][0] not in shuju_zidian1:
                    shuju_zidian1[indexed_items[i][0]] = {}  # 如果没有该键，先创建一个空字典
                shuju_zidian1[indexed_items[i][0]] = quxianluru(indexed_items[i][0], data_x, data_y1, line_chart,
                                                                axis_x, axis_y, self.colors[i])  # 录入一条曲线并设置名称

        chart_view = chartview.ChartView(line_chart, list(self.key_v_data.items()),
                                         shuju_zidian1,max_y)  # 这里假设你已定义了 ChartView 类
        # 启用渲染优化
        chart_view.setRenderHint(QPainter.Antialiasing, True)
        chart_view.chart().legend().setAlignment(Qt.AlignBottom)
        chart_view.chart().legend().show()

        return chart_view

    def update_status(self):  # 点击多选框事件
        checkboxed = {}
        checkboxed[self.checkBox.text()] = self.checkBox.isChecked()
        checkboxed[self.checkBox_2.text()] = self.checkBox_2.isChecked()
        checkboxed[self.checkBox_3.text()] = self.checkBox_3.isChecked()
        checkboxed[self.checkBox_4.text()] = self.checkBox_4.isChecked()
        checkboxed[self.checkBox_5.text()] = self.checkBox_5.isChecked()
        checkboxed[self.checkBox_6.text()] = self.checkBox_6.isChecked()
        checkboxed[self.checkBox_7.text()] = self.checkBox_7.isChecked()
        checkboxed[self.checkBox_8.text()] = self.checkBox_8.isChecked()
        checkboxed[self.checkBox_9.text()] = self.checkBox_9.isChecked()
        checkboxed[self.checkBox_10.text()] = self.checkBox_10.isChecked()
        checkboxed[self.checkBox_11.text()] = self.checkBox_11.isChecked()
        checkboxed[self.checkBox_12.text()] = self.checkBox_12.isChecked()
        checkboxed[self.checkBox_13.text()] = self.checkBox_13.isChecked()
        checkboxed[self.checkBox_14.text()] = self.checkBox_14.isChecked()
        checkboxed[self.checkBox_15.text()] = self.checkBox_15.isChecked()
        checkboxed[self.checkBox_16.text()] = self.checkBox_16.isChecked()
        checkboxed[self.checkBox_17.text()] = self.checkBox_17.isChecked()
        checkboxed[self.checkBox_18.text()] = self.checkBox_18.isChecked()

        # 指定要操作的JSON文件名
        json_file = 'H_S_JSON/legend.json'

        # 检查文件是否存在
        if os.path.exists(json_file):
            # 从 JSON 文件读取字典
            with open(json_file, 'r') as file:
                data1 = json.load(file)
        else:
            # 如果文件不存在，初始化一个新的字典
            data1 = {}

        data = checkboxed
        # 当前数据的更新缓存
        # self.indexed_items = list(data.items())
        # self.line_chart.key_v_data = self.indexed_items

        for i in data.keys():
            data1[i] = data[i]

        # self.key_v_data = data
        # 输出当前数据
        # print("当前数据:", data)
        # 将更新后的字典写入 JSON 文件
        with open(json_file, 'w') as file:
            json.dump(data1, file, indent=4)  # indent 参数用于格式化输出，增加可读性

        self.clear_layout(self.horizontalLayout)
        self.show_chart()

    def clear_layout(self, layout1):
        # 逆序遍历避免索引错乱
        for i in reversed(range(layout1.count())):
            item = layout1.itemAt(i)
            widget = item.widget()
            # 仅删除 QTabWidget 类型的控件
            if isinstance(widget, QTabWidget):
                widget.deleteLater()
                layout1.removeItem(item)  # 从布局中移除

    def pushButton_clicked(self):  # 一键复位按钮，按下事件
        # 获取布局中的对象，使其位置与缩放复位
        item = self.horizontalLayout.itemAt(1)

        # 检查 item 是否为 None
        if item is None:
            print("No item found in the layout.")
            return
        widget = item.widget()
        if widget is None:
            print("The item does not contain a widget.")
            return
        # print(widget)
        # 获取当前选中的标签页索引
        # 获取选中的标签页
        selected_widget = widget.widget(widget.currentIndex())

        for child in selected_widget.findChildren(QWidget):
            # print(child)
            # 如果子控件是 QTabWidget 类型，则打印它
            if isinstance(child, QChartView):
                chart1 = child.chart()
                chart1.zoomReset()
                # return

    def pushButton_2_clicked(self):  # 3D图像缩放按钮，按下事件
        if self._container.size().width() > 400:
            self._container.setFixedSize(180, 540)
        else:
            self._container.setFixedSize(600, 540)

    # --------------实时数据初始化更新方法------------------
    # 3D焊接过程实时显示初始化
    def runtime_3D_init(self):
        # ---------------------实时3D图像初始化---------------------
        # 指定要操作的JSON文件名
        json_file = 'H_S_JSON/System_settings.json'
        # 从 JSON 文件读取字典
        with open(json_file, 'r') as file:
            key_v_data = json.load(file)
        self.surface = CustomScatter()  # 3D容器
        self.surface.setShadowQuality(QAbstract3DGraph.ShadowQuality.ShadowQualityNone)    # 去除绘图对象的阴影
        axis = self.surface.axisX()  # 三轴初始化
        axis.setTitle("X")
        axis.setTitleVisible(True)
        axis.setRange(key_v_data["3Dline"]["X_min"], key_v_data["3Dline"]["X_max"])  # 设置X轴范围
        axis = self.surface.axisY()
        axis.setTitle("Z")
        axis.setTitleVisible(True)
        axis.setRange(key_v_data["3Dline"]["Z_min"], key_v_data["3Dline"]["Z_max"])
        axis = self.surface.axisZ()
        axis.setTitle("Y")
        axis.setTitleVisible(True)
        axis.setRange(key_v_data["3Dline"]["Y_min"], key_v_data["3Dline"]["Y_max"])
        self._container = QWidget.createWindowContainer(self.surface)
        self._container.setFixedSize(180, 540)  # 设置3D图表大小
        self._container.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self._container.setFocusPolicy(Qt.StrongFocus)

        self.verticalLayout_2.addWidget(self._container)  # 多选按钮下方布局内添加3D图表
        self.data_3D = []
        self.data_xyz = []
        self.data_nowp = []
        self.data_dianhan = []
        self.data_police_c = []
        self.series_chocked = None
        self.series_chock_old = None
        # 元素类型	   曲线A	         异常点
        # 主曲线	  #1F77B4 (钴蓝)	  	   -
        # 当前点	  #4C72B0	      #D62728 (正红)
        # 电焊点	  #2CA02C (青绿)	  	   -

        # A绘制点
        self.series_A = QScatter3DSeries()  # 3D数据框架
        self.series_A.setBaseColor(QColor(44, 95, 138))  # A设置颜色QColor(31, 119, 180)    点QColor(76, 114, 176)     点焊QColor(44, 160, 44)     报警点QColor(214, 39, 40)
        self.series_A.setItemSize(0.05)  # 设置点大小      # B设置颜色QColor(255, 127, 14)    点QColor(213, 94, 0)       点焊QColor(148, 103, 189)
        self.series_A.setMeshSmooth(True)  # 设置平滑
        self.series_A.setMesh(QAbstract3DSeries.MeshPoint)  # 设置形状 - 指向点

        # A 点焊点
        self.dianhan_A = QScatter3DSeries()  # 3D数据框架
        self.dianhan_A.setBaseColor(QColor(148, 145, 182))
        self.dianhan_A.setItemSize(0.08)  # 设置点大小
        self.dianhan_A.setMeshSmooth(True)  # 设置平滑
        self.dianhan_A.setMesh(QAbstract3DSeries.MeshPoint)  # 设置形状 - 指向点

        # 报警点
        self.police_c = QScatter3DSeries()  # 3D数据框架
        self.police_c.setBaseColor(QColor(193, 39, 45))
        self.police_c.setItemSize(0.05)  # 设置点大小
        self.police_c.setMeshSmooth(True)  # 设置平滑
        self.police_c.setMesh(QAbstract3DSeries.MeshArrow)  # 设置形状 - 指向点

        # 鼠标指示点
        self.zhishi_c = QScatter3DSeries()  # 3D数据框架
        self.zhishi_c.setBaseColor(QColor(255, 255, 255))
        self.zhishi_c.setItemSize(0.05)  # 设置点大小
        self.zhishi_c.setMeshSmooth(True)  # 设置平滑
        self.zhishi_c.setMesh(QAbstract3DSeries.MeshSphere)  # 设置形状 - 指向点

        self.surface.addSeries(self.series_A)
        self.surface.addSeries(self.dianhan_A)
        self.surface.addSeries(self.police_c)
        self.surface.addSeries(self.zhishi_c)

        self.surface.selectedSeriesChanged.connect(self.on_scatter_point_clicked)
        # 连接场景点击信号
        self.surface.clickValidated.connect(self.handle_viewport_click)
        # -----------------------------------------------------

    # 3D图像散点被点击事件
    def on_scatter_point_clicked(self, series):
        self.series_chocked = series
        if series == self.series_A:
            selected_point_index = series.selectedItem()
            point = series.dataProxy().itemAt(selected_point_index)
            x = point.x()
            y = point.y()
            z = point.z()
            # print(f"A点击的坐标为：", self.time_xyz_A)
            for v in self.time_xyz:
                # print(v[1:3])
                if v[3] == x and v[4] == y and v[5] == z:
                    for index in range(self.main_tab.count()):          # 进行翻页操作 从存储的坯组与边号信息进行翻页跳转
                        if self.main_tab.tabText(index) == "坯组编号：" + str(v[1]):
                            self.main_tab.setCurrentIndex(index)
                            for index1 in range(self.outer_tab[v[1]].count()):
                                if self.outer_tab[v[1]].tabText(index1) == "边号：" + str(v[2]):
                                    self.outer_tab[v[1]].setCurrentIndex(index1)
                    # self.main_tab.to_bytes()
                    self.chart_view[str(v[1])+"-"+str(v[2])].show_yun(v[0])
                    # print(f"A点击的时间为：({k})")

    # 3D图像点击空白处事件
    def handle_viewport_click(self):
        # 当点击空白区域时主动清除选中状态
        if self.series_chocked == self.series_chock_old:
            self.series_chock_old = None
            for key, view in self.chart_view.items():
                view.close_yun()
            print("点中空白处")
        elif self.series_chocked != None and self.series_chock_old == None:
            print("点中异点处")
            self.series_chock_old = self.series_chocked
        elif self.series_chocked != self.series_chock_old:
            print("点中异点处")
            self.series_chock_old = self.series_chocked
        elif self.series_chocked == None and self.series_chock_old != None:
            self.series_chock_old = None
            for key, view in self.chart_view.items():
                view.close_yun()
            print("点中空白处")

